----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/code/logs/figure_F1_exportcorrection.log
  log type:  text
 opened on:  18 Dec 2022, 03:57:25

. *-------------------------------------------------------------------------------
. 
. 
. 
. 
. 
. *Manufacturing Only: adjusting the baseline to have the same firms as the one excluding exports
. *--------------------------------------------------------------------------
. clear all

. use "${data}/estimates_aggtype_naics_sales_s1_robust_woparent_exclexp.dta", clear

. 
. rename D_A xx

. rename D_A_se xx_se

. merge 1:1 year isocode type using "${data}/estimates_aggtype_naics_sales_s1_base_woparent_exclexp.dta", keepusing(D_A D_A_se)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                                81  (_merge==3)
    -----------------------------------------

. drop _merge

. keep if type=="manuf"
(54 observations deleted)

. rename D_A DA_base

. rename D_A_se DA_se_base

. rename xx DA_exp

. rename xx_se DA_se_exp

. 
. gen dummy=0

. foreach xx in DE EE FR GB GR HR HU SI {
  2. display "`xx'"
  3. replace dummy=1 if isocode=="`xx'"
  4. }
DE
(1 real change made)
EE
(1 real change made)
FR
(1 real change made)
GB
(1 real change made)
GR
(1 real change made)
HR
(1 real change made)
HU
(1 real change made)
SI
(1 real change made)

. keep if dummy==1
(19 observations deleted)

. 
. gen u_DA_base = DA_base + 1.96 * DA_se_base

. gen l_DA_base = DA_base - 1.96 * DA_se_base 

. gen u_DA = DA_exp + 1.96 * DA_se_exp 

. gen l_DA = DA_exp - 1.96 * DA_se_exp 

. 
. keep year isocode type u_DA_base l_DA_base u_DA l_DA DA_base DA_exp

. 
. gsort DA_base

. gen num=1 if isocode=="EE"
(7 missing values generated)

. replace num=2 if isocode=="SI"
(1 real change made)

. replace num=3 if isocode=="HR"
(1 real change made)

. replace num=4 if isocode=="HU"
(1 real change made)

. replace num=5 if isocode=="GR"
(1 real change made)

. replace num=6 if isocode=="GB"
(1 real change made)

. replace num=7 if isocode=="FR"
(1 real change made)

. replace num=8 if isocode=="DE"
(1 real change made)

. gsort -num

. 
. drop year

. gen t=_n

. sum t

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
           t |          8         4.5     2.44949          1          8

. 
. sum t

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
           t |          8         4.5     2.44949          1          8

. forvalues ii=1(1)`r(max)' {
  2. local ctry`ii' = isocode[`ii']
  3. local obs`ii' = `ii'
  4. display "`ctry`ii'' ; `obs`ii''"
  5. }
DE ; 1
FR ; 2
GB ; 3
GR ; 4
HU ; 5
HR ; 6
SI ; 7
EE ; 8

. 
. twoway rcap u_DA_base l_DA_base t, lc(red) /// 
> ||     rcap u_DA l_DA t, lc(blue) /// 
> ||     scatter DA_base t, mc(red)  /// 
> ||     scatter DA_exp t, mc(blue)  ///
> yline(0) yline(0) ylab(-2(1)4) xlab(1(1)8)  xlabel(, valuelabel) xlabel(, angle(45)) ytitle("") xtitle("") graphregion(fcolor(white) lcolor(white)) xlabel(`obs1' "`ctry1'" `obs
> 2' "`ctry2'"  `obs3' "`ctry3'" `obs4' "`ctry4'" `obs5' "`ctry5'" `obs6' "`ctry6'" `obs7' "`ctry7'" `obs8' "`ctry8'", labsize(small)) legend(order(3 "Baseline (adjusted)" 4 "Exp
> ort correction") rows(1) size(small) bplace(n) ring(0) region(lwidth(none)))

. display "fig1_`title'_`yy'"
fig1__

. graph export "${rappendix}/fig_F1_exclexports_manufacturing.pdf", replace
(file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/appendix/fig_F1_exclexports_manufacturing.pdf 
> written in PDF format)

. 
. 
. 
. *Aggregate: adjusting the baseline to have the same firms as the one excluding exports
. *--------------------------------------------------------------------------
. clear all

. use "${data}/estimates_agg_naics_sales_s1_robust_woparent_exclexp.dta", clear

. 
. rename D_A xx

. rename D_A_se xx_se

. merge 1:1 year isocode using "${data}/estimates_agg_naics_sales_s1_base_woparent_exclexp.dta", keepusing(D_A D_A_se)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                                27  (_merge==3)
    -----------------------------------------

. drop _merge

. 
. rename D_A DA_base

. rename D_A_se DA_se_base

. rename xx DA_exp

. rename xx_se DA_se_exp

. 
. gen dummy=0

. foreach xx in DE EE FR GB GR HR HU SI {
  2. display "`xx'"
  3. replace dummy=1 if isocode=="`xx'"
  4. }
DE
(1 real change made)
EE
(1 real change made)
FR
(1 real change made)
GB
(1 real change made)
GR
(1 real change made)
HR
(1 real change made)
HU
(1 real change made)
SI
(1 real change made)

. keep if dummy==1
(19 observations deleted)

. 
. gen u_DA_base = DA_base + 1.96 * DA_se_base 

. gen l_DA_base = DA_base - 1.96 * DA_se_base 

. gen u_DA = DA_exp + 1.96 * DA_se_exp 

. gen l_DA = DA_exp - 1.96 * DA_se_exp 

. 
. keep year isocode type u_DA_base l_DA_base u_DA l_DA DA_base DA_exp

. foreach vv in u_DA_base l_DA_base u_DA l_DA DA_base DA_exp {
  2. display "`vv'"
  3. }
u_DA_base
l_DA_base
u_DA
l_DA
DA_base
DA_exp

. gsort DA_base

. gen num=1 if isocode=="SI"
(7 missing values generated)

. replace num=2 if isocode=="EE"
(1 real change made)

. replace num=3 if isocode=="HR"
(1 real change made)

. replace num=4 if isocode=="GR"
(1 real change made)

. replace num=5 if isocode=="HU"
(1 real change made)

. replace num=6 if isocode=="GB"
(1 real change made)

. replace num=7 if isocode=="FR"
(1 real change made)

. replace num=8 if isocode=="DE"
(1 real change made)

. **gsort -num
. drop year

. gen t=_n

. sum t

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
           t |          8         4.5     2.44949          1          8

. 
. sum t

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
           t |          8         4.5     2.44949          1          8

. forvalues ii=1(1)`r(max)' {
  2. local ctry`ii' = isocode[`ii']
  3. local obs`ii' = `ii'
  4. display "`ctry`ii'' ; `obs`ii''"
  5. }
DE ; 1
FR ; 2
GB ; 3
GR ; 4
HU ; 5
HR ; 6
SI ; 7
EE ; 8

. 
. 
. twoway rcap u_DA_base l_DA_base t, lc(red) /// 
> ||     rcap u_DA l_DA t, lc(blue) /// 
> ||     scatter DA_base t, mc(red)  /// 
> ||     scatter DA_exp t, mc(blue)  ///
> yline(0) yline(0) ylab(-2(1)4) xlab(1(1)8)  xlabel(, valuelabel) xlabel(, angle(45)) ytitle("") xtitle("") graphregion(fcolor(white) lcolor(white)) xlabel(`obs1' "`ctry1'" `obs
> 2' "`ctry2'"  `obs3' "`ctry3'" `obs4' "`ctry4'" `obs5' "`ctry5'" `obs6' "`ctry6'" `obs7' "`ctry7'" `obs8' "`ctry8'", labsize(small)) legend(order(3 "Baseline (adjusted)" 4 "Exp
> ort correction") rows(1) size(small) bplace(n) ring(0) region(lwidth(none)))

. display "fig1_`title'_`yy'"
fig1__

. graph export "${rappendix}/fig_exclexports_aggregate.pdf", replace
(file F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files/results/appendix/fig_exclexports_aggregate.pdf written
>  in PDF format)

. 
. 
end of do-file

. use "${data}/pre_reg0_naics_sales_s1_base_woparent_2016.dta", clear

. global typeden=1

. 
. include "set_directories.do"

. /***************************************************************************************
> Firm-embedded productivity and cross-country income differences
> Alviarez, Cravino and Ramondo
> Journal of Political Economy (2022)
> 
> Program: set_directories.do
> Date: October 2022
> 
> Description: Sets directory paths
> *****************************************************************************************/
. 
. *Set root directory here
. global root "F:/Dropbox (UBC-Umich)/Research_Projects/Project Javier and Natalia/TFP firm/TFP_firm_data_historical/dataverse_files" 

. 
. 
. *All other directories set automatically
. 
. *Code
. global code "${root}/code"

. global clogs "${root}/code/logs"

. global cmain "${root}/code/main" /*Code to produce figues and tables in the main text */

. global cappendix "${root}/code/appendix" /*Code to produce figues and tables in the appendix */

. 
. *Data
. global data "${root}/data/analysis"

. global tmp  "${root}/data/tmp"

. 
. *Results
. global rmain "${root}/results/main" /*Figues and tables in the main text */

. global rappendix  "${root}/results/appendix" /*Figues and tables in the appendix */

. 
. 
. *Whether the denominator used to construct the aggregate sales shares exclude or not exports
. if $typeden==0 {
. local denominator "_exp_ko"
. }

. if $typeden==1 {
. local denominator "_ko"
. }

. *
. 
. 
. /*******************************************************************************
> *Stata packages to install:
>    1) gtools
>    2) reghdfe
> *******************************************************************************/
. 
. 
. 
. 
. 
. 
. . 
. set memory 64g
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. 
. global lf "LF"

. 
. 
. 
. *Log

. 
. cap log close
